// datetime_utils.dart
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:flutter/material.dart';
import 'package:toys_flutter/pages/LoginPage.dart';

class DateTimeUtils {
  /// 将时间戳转换为格式化的日期字符串
  static String convertTimestampToDateString(int timestamp) {
    // 将秒转换为毫秒
    DateTime date = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000);
    // 格式化日期
    String formattedDate = DateFormat('yyyy-MM-dd HH:mm:ss').format(date);
    return formattedDate;
  }
}

// 显示登录失效的弹框
class LoginExpiredDialog extends StatelessWidget {
  const LoginExpiredDialog({super.key});

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      title: const Text('登录失效'),
      content: const Text('您的登录已失效，请重新登录。'),
      actions: [
        TextButton(
          style: ButtonStyle(
            backgroundColor: WidgetStateProperty.all(Colors.transparent),
            foregroundColor: WidgetStateProperty.all(Colors.black),
          ),
          onPressed: () {
            Navigator.of(context).pop();
          },
          child: const Text('取消'),
        ),
        TextButton(
          onPressed: () {
            Navigator.of(context).pop();
            Get.to(const LoginPage());
          },
          child: const Text('重新登录'),
        ),
      ],
    );
  }
}
